package org.example.volunteerend.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.example.volunteerend.entity.ProjectCategory;

@Mapper
public interface ProjectCategoryMapper {
    @Select("SELECT category_id, category_name, description, icon_url FROM project_categories ORDER BY category_id")
    List<ProjectCategory> findAll();
    
    @Select("SELECT category_id, category_name, description, icon_url FROM project_categories WHERE category_id = #{categoryId}")
    ProjectCategory findById(Integer categoryId);
    
    /**
     * 根据分类名称查询分类
     */
    @Select("SELECT category_id, category_name, description, icon_url FROM project_categories WHERE category_name = #{categoryName}")
    ProjectCategory findByCategoryName(String categoryName);
    
    /**
     * 添加新分类
     */
    @Insert("INSERT INTO project_categories (category_name, description, icon_url) VALUES (#{categoryName}, #{description}, #{iconUrl})")
    @Options(useGeneratedKeys = true, keyProperty = "categoryId")
    int insert(ProjectCategory category);
    
    /**
     * 更新分类图标
     */
    @Update("UPDATE project_categories SET icon_url = #{iconUrl} WHERE category_id = #{categoryId}")
    int updateIconUrl(@Param("categoryId") Integer categoryId, @Param("iconUrl") String iconUrl);
} 